package com.fh.controller;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.fh.model.User;
import com.fh.service.UserService;


@Controller
@RequestMapping(value="/admin")
public class UserController{
	
	
	@Autowired
	private UserService userService;
	
	/**保存
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/findUser",method= RequestMethod.POST)
	public String save(User user,HttpSession session) throws Exception{
		User user2=userService.findByUser(user);
		if(user2!=null){
			System.out.println("登陆");
			session.setAttribute("user", user2);
			return "admin/index";
		}
		return "redirect:/admin/login.do";
	}
	
	@InitBinder
	public void initBinder(WebDataBinder binder){
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		binder.registerCustomEditor(Date.class, new CustomDateEditor(format,true));
	}
}
